package net.jgrm.idgenerator.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * ID生成器配置属性类
 */
@Data
@Component
@ConfigurationProperties(prefix = "id.generator")
public class IdGeneratorProperties {

    /**
     * ID生成器类型，支持：snowflake, redis
     */
    private String type = "snowflake";

    /**
     * 雪花算法配置
     */
    private Snowflake snowflake = new Snowflake();

    /**
     * Redis配置
     */
    private Redis redis = new Redis();

    /**
     * 雪花算法配置内部类
     */
    @Data
    public static class Snowflake {

        /**
         * 数据中心ID
         */
        private long dataCenterId = 1;

        /**
         * 机器ID
         */
        private long workerId = 1;
    }

    /**
     * Redis配置内部类
     */
    @Data
    public static class Redis {

        /**
         * Redis键前缀
         */
        private String keyPrefix = "id:generator";

        /**
         * 默认自增步长
         */
        private long step = 1;

        /**
         * key过期时间（秒），默认7天
         */
        private long expire = 604800;
    }
}